package main

import (
	"flag"
	"fmt"
	"io"
	"net/http"
	"os"

	"gitee.com/thubcc/p2pgit/some"
	"gitee.com/thubcc/p2pgit/types"
	"github.com/gin-gonic/gin"
)

var (
	argNewPack = flag.String("n", "../temp", "New Pack Dir")
	argPort    = flag.String("p", "8080", "http port")
	argLog     = flag.String("l", "gin.log", "gin log file")
)

func main() {
	flag.Parse()
	gs, err := some.GeterFromDir(*argNewPack)
	if err != nil {
		fmt.Println(err)
		return
	}
	rs := types.NewRawer(some.Geter2Rawer(gs))

	r := gin.Default()

	gin.DisableConsoleColor()
	f, _ := os.Create(*argLog)
	gin.DefaultWriter = io.MultiWriter(f)

	some.Handle(&rs, r)
	fmt.Fprintln(gin.DefaultWriter, ":"+*argPort, "online")
	http.ListenAndServe(":"+*argPort, r)
}
